package com.jike.noobmoney.mvp.view.activity;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.google.gson.Gson;
import com.image.imagepicker.ImagePicker;
import com.image.imagepicker.bean.ImageItem;
import com.image.imagepicker.ui.ImageGridActivity;
import com.image.imagepicker.ui.ImagePreviewDelActivity;
import com.jike.noobmoney.R;
import com.jike.noobmoney.adapter.ImagePickerAdapter;
import com.jike.noobmoney.adapter.TaskDetailUnAdapter;
import com.jike.noobmoney.contants.ConstantValue;
import com.jike.noobmoney.entity.BaseEntity;
import com.jike.noobmoney.entity.SubmitOrderDetailEntity;
import com.jike.noobmoney.entity.TaskDetailEntity;
import com.jike.noobmoney.entity.UploadFilesEntity;
import com.jike.noobmoney.entity.UploadPicEntity;
import com.jike.noobmoney.helper.ImageLoader;
import com.jike.noobmoney.mvp.presenter.AppPresenter;
import com.jike.noobmoney.mvp.view.widget.BuHeGeDialog;
import com.jike.noobmoney.net.IView;
import com.jike.noobmoney.net.RetrofitHelper;
import com.jike.noobmoney.util.AppUtils;
import com.jike.noobmoney.util.ComUtils;
import com.jike.noobmoney.util.Constant;
import com.jike.noobmoney.util.Logger;
import com.jike.noobmoney.util.SPUtils;
import com.jike.noobmoney.util.SignUtil;
import com.jike.noobmoney.util.ToastUtils;
import com.umeng.commonsdk.debug.E;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.TreeMap;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import me.iwf.photopicker.PhotoPreview;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * 上传图片改成单选
 */
public class UnFinishTaskActivity extends BaseActivity implements ImagePickerAdapter.OnRecyclerViewItemClickListener, IView {

    public static final String t_id = "t_id";
    public static final String o_id = "o_id";
    public static final int IMAGE_ITEM_ADD = -1;
    private int maxImgCount = 9;               //允许选择图片最大数
    private ArrayList<ImageItem> selImageList; //当前选择的所有图片
    public static final int REQUEST_CODE_PREVIEW = 101;
    public static final int REQUEST_CODE_SELECT = 100;

    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.iv_task_img)
    ImageView ivTaskImg;
    @BindView(R.id.tv_task_title)
    TextView tvTaskTitle;
    @BindView(R.id.tv_task_remain)
    TextView tvTaskRemain;
    @BindView(R.id.tv_task_money)
    TextView tvTaskMoney;
    @BindView(R.id.tv_terminal)
    TextView tvTerminal;
    @BindView(R.id.tv_user)
    TextView tvUser;
    @BindView(R.id.tv_submit)
    TextView tvSubmit;
    @BindView(R.id.webview)
    WebView webview;
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;

    @BindView(R.id.tv_text)
    TextView tvText;
    @BindView(R.id.ll_image)
    LinearLayout llImage;

    @BindView(R.id.recyclerview)
    RecyclerView recyclerview;
    @BindView(R.id.tv_type_title)
    TextView tvTypeTitle;
    @BindView(R.id.tv_type)
    TextView tvType;
    @BindView(R.id.iv_ecode)
    ImageView ivEcode;
    @BindView(R.id.tv_http)
    TextView tvHttp;

    @BindView(R.id.et_tj)
    EditText et_tj;

    private String taskId;
    private String orderId;
    private String userid;
    private Call<SubmitOrderDetailEntity> taskDetail;
    private ImagePickerAdapter adapter;
    private Call<BaseEntity> cancleOrder;
    private Call<BaseEntity> submitOrder;
    private AppPresenter appPresenter;

    private TaskDetailUnAdapter detailAdapter;
    private List<SubmitOrderDetailEntity.OrderinfoBean.TaskstepBean> mData = new ArrayList<>();
    private int nowPosition = -1;

    @BindView(R.id.tv_task_id)
    TextView tv_task_id;

    @BindView(R.id.tv_tijiaotime)
    TextView tv_tijiaotime;
    @BindView(R.id.tv_jiedantime)
    TextView tv_jiedantime;

    @BindView(R.id.tv_user_id)
    TextView tv_user;

    @BindView(R.id.tv_u_id)
    TextView tv_u_id;

    @BindView(R.id.tv_finish_percent)
    TextView  tv_finish_percent;

    @BindView(R.id.tv_ll)
    LinearLayout tv_ll;

    @BindView(R.id.tv_sx)
    TextView tv_sx;

    String isinfo="";

    /**
     * 如果要全屏,重写这个方法返回false
     */
    public Boolean isfits() {
        return true;
    }

    /**
     * 如果要白色主题,重写这个方法返回false
     */
    public boolean ismain() {
        return true;
    }
    @Override
    protected int layoutResID() {
        return R.layout.activity_unfinish_task_update;
    }

    @Override
    protected void initData() {
        if (getIntent() != null) {
            taskId = getIntent().getStringExtra(UnFinishTaskActivity.t_id);
            orderId = getIntent().getStringExtra(UnFinishTaskActivity.o_id);
        }
        userid = SPUtils.getInstance().getString(ConstantValue.SpType.userid);
        tvTitle.setText("任务详情");
        setWebsetting();
        getData();

        appPresenter = new AppPresenter(this);    //上传图片

        selImageList = new ArrayList<>();
        adapter = new ImagePickerAdapter(this, selImageList, maxImgCount);
        adapter.setOnItemClickListener(this);
        recyclerView.setLayoutManager(new GridLayoutManager(this, 3));
        recyclerView.setHasFixedSize(true);
        recyclerView.setAdapter(adapter);


        //adapter
        detailAdapter = new TaskDetailUnAdapter(context, position -> {
            nowPosition = position;
            ImagePicker.getInstance().setSelectLimit(1);
            ImagePicker.getInstance().setCrop(false);
            ImagePicker.getInstance().setShowCamera(true);
            ImagePicker.getInstance().setMultiMode(true);
            Intent intent1 = new Intent(context, ImageGridActivity.class);
            startActivityForResult(intent1, 201);
        });
        //manager
        recyclerview.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
        recyclerview.setAdapter(detailAdapter);
        recyclerview.setNestedScrollingEnabled(false);

    }

    /**
     * 获取数据
     */
    private void getData() {
        showProgress();
        Log.e("xuke", "userid = " + userid + ",taskid=" + taskId);
        taskDetail = RetrofitHelper.getInstance().submitOrderDetail(orderId);
        taskDetail.enqueue(new Callback<SubmitOrderDetailEntity>() {
            @Override
            public void onResponse(Call<SubmitOrderDetailEntity> call, Response<SubmitOrderDetailEntity> response) {
                if (response != null) {
                    SubmitOrderDetailEntity body = response.body();
                    if (body != null) {
                        if ("100".equals(body.getCode())) {
                            setView(body);
                        } else {
                            ToastUtils.showShortToastSafe(body.getRinfo());
                        }
                    }
                    dismissProgress();
                }
            }

            @Override
            public void onFailure(Call<SubmitOrderDetailEntity> call, Throwable t) {
                ToastUtils.showShortToastSafe(t.getMessage());
                dismissProgress();
            }
        });


    }

    /**
     * 设置视图
     */
    private void setView(SubmitOrderDetailEntity body) {
        SubmitOrderDetailEntity.OrderinfoBean taskinfo = body.getOrderinfo();
        if (taskinfo != null) {

            tvTaskTitle.setText("任务名称:" + (TextUtils.isEmpty(taskinfo.getTaskname()) ? "小白任务" : taskinfo.getTaskname()));

            tv_tijiaotime.setText("接单时间：" + taskinfo.getCreatetime());
            tv_jiedantime.setText("提交时间：" + taskinfo.getSubmittime());

            tvText.setText(taskinfo.tasktext);

            tv_task_id.setText("任务ID:" + taskinfo.getT_id());

            tv_user.setText("接单人:" + taskinfo.getU_id());

            tv_u_id.setText("用户ID:" + taskinfo.getU_id() + "");

            tv_finish_percent.setText("历史任务通过率:" + ComUtils.getPercent(taskinfo.finishpercent));

//        String image = taskinfo.getImage();
//        String[] result = image.split(",");
//        for (int i = 0; i < result.length; i++) {
//            String s = result[i];
//            String url = ConstantValue.IMG_BASEURL + s;
//            addImg(url);
//        }

            //控制申述的显示与否
            int status=taskinfo.getStatus();
            if(status==1){
                tv_sx.setVisibility(View.GONE);

            }else if(status==2)
            {
                tv_sx.setVisibility(View.VISIBLE);
            }


            int opentype = taskinfo.getOpentype(); //1二维码  2链接
            String openurl = taskinfo.getOpenurl();
            if (opentype == 1) {
                tvType.setText("二维码");
                ivEcode.setVisibility(View.VISIBLE);
                tvHttp.setVisibility(View.GONE);
                Glide.with(this).load(ConstantValue.IMG_BASEURL_QR_CODE + openurl).into(ivEcode);
            } else if (opentype == 2) {
                tvType.setText("链接");
                ivEcode.setVisibility(View.GONE);
                tvHttp.setVisibility(View.VISIBLE);
                tvHttp.setText(openurl);
            } else {
                tvTypeTitle.setVisibility(View.GONE);
                tvType.setVisibility(View.GONE);
                ivEcode.setVisibility(View.GONE);
                tvHttp.setVisibility(View.GONE);
            }

            ivEcode.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    ArrayList<String> photoPaths = new ArrayList<>();
                    photoPaths.add(ConstantValue.IMG_BASEURL_QR_CODE + openurl);
                    PhotoPreview.builder()
                            .setPhotos(photoPaths)
                            .setCurrentItem(0)
                            .setShowDeleteButton(true)
                            .start((Activity) context);
                }
            });

            isinfo= taskinfo.isinfo;
           if(isinfo.equals("0")){
            tv_ll.setVisibility(View.GONE);
           }else {
               tv_ll.setVisibility(View.VISIBLE);
               //et_tj.setText(taskinfo.getInfo());
           }


            //步骤
            List<SubmitOrderDetailEntity.OrderinfoBean.TaskstepBean> taskstep = taskinfo.getTaskstep();
            if (taskstep != null) {
                mData.clear();
                mData.addAll(taskstep);
            }
            detailAdapter.refresh(mData);

        }
    }

//    private void addImg(String url) {
//        ImageView newImg = new ImageView(this);
//        //设置想要的图片，相当于android:src="@drawable/image"
//        //newImg.setImageResource(R.mipmap.ic_launcher);
//        ImageLoader.displayImage(this, url, newImg);
//
//        //设置子控件在父容器中的位置布局，wrap_content,match_parent
//        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
//                ViewGroup.LayoutParams.MATCH_PARENT,
//                ViewGroup.LayoutParams.WRAP_CONTENT);
//        // 也可以自己想要的宽度，参数（int width, int height）均表示px
//        // 如dp单位，首先获取屏幕的分辨率在求出密度，根据屏幕ppi=160时，1px=1dp
//        //则公式为 dp * ppi / 160 = px ——> dp * dendity = px
//        //如设置为48dp：1、获取屏幕的分辨率 2、求出density 3、设置
//        DisplayMetrics displayMetrics = new DisplayMetrics();
//        getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
//        float density = displayMetrics.density;
//        LinearLayout.LayoutParams params1 = new LinearLayout.LayoutParams(
//                (int) (48 * density),
//                (int) (48 * density));
//        //相当于android:layout_marginLeft="8dp"
//        params.leftMargin = 20;
//        params.rightMargin = 20;
//        params.topMargin = 20;
//        //addView(View child)，默认往已有的view后面添加，后插入，不设置布局params,默认wrap_content
//        //llImage.addView(newImg);
//        //addView(View child, LayoutParams params)，往已有的view后面添加，后插入,并设置布局
//        llImage.addView(newImg, params);
//    }

    @SuppressWarnings("deprecation")
    @SuppressLint({"SetJavaScriptEnabled", "AddJavascriptInterface"})
    private void setWebsetting() {
        WebSettings webSettings = webview.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webview.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
        webSettings.setDefaultTextEncodingName("UTF-8");
        webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
        webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
        webSettings.setSupportMultipleWindows(true);
        webSettings.setBuiltInZoomControls(false);
        webSettings.setSupportZoom(false);
        webSettings.setDisplayZoomControls(false);
        webSettings.setPluginState(WebSettings.PluginState.ON);
        webSettings.setDomStorageEnabled(true);
        webSettings.setLoadsImagesAutomatically(true);
        webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);

        webview.clearCache(true);
        webview.clearHistory();
    }

    @OnClick({R.id.iv_back, R.id.tv_order, R.id.tv_cancle,R.id.tv_sx})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                finish();
                break;
            case R.id.tv_order:
                //提交审核
                submitOrderNew();
                break;
            case R.id.tv_sx:
                //投诉
                if (AppUtils.isFastClick()) {
                    ToastUtils.showShortToastSafe("操作有点频繁,稍后重试");
                    return;
                }
                BuHeGeDialog jiaPiaoDialog1 = BuHeGeDialog.getInstance();
                jiaPiaoDialog1.show(getSupportFragmentManager(), "buhege1");
                jiaPiaoDialog1.setClickCallback(number -> {
                    //确认
                    jiaPiaoDialog1.dismiss();
                    setAppealOrder(number);
                });

                break;
            case R.id.tv_cancle:
                //取消
                if (AppUtils.isFastClick()) {
                    ToastUtils.showShortToastSafe("操作有点频繁,稍后重试");
                    return;
                }
                setCancleOrder();
                break;
        }
    }

    /**
     * 上传图片
     */
    private void uploadFiles() {
        showProgress();
        if (selImageList != null && selImageList.size() > 0) {
            appPresenter.uploadFiles2(selImageList, ConstantValue.RequestKey.uploadfiles);
            //appPresenter.upload(new File(selImageList.get(0).getPath()), ConstantValue.RequestKey.uploadfile);
        } else {
            dismissProgress();
            ToastUtils.showShortToastSafe("请上传图片");
        }
    }

    /**
     * 提交任务
     */
    public void submitOrder(String url) {
        String info = "";

//        String picstr = "";
//        StringBuilder stringBuilder = new StringBuilder(picstr);
//        if (selImageList != null && selImageList.size() > 0) {
//            Log.e("xuke", "----" + selImageList.size());
//            for (int i = 0; i < selImageList.size(); i++) {
//                ImageItem imageItem = selImageList.get(i);
//                String path = imageItem.getPath();
//                String picPath = "data:image/jpeg;base64," + AppUtils.file2Base64(path);
//                if (TextUtils.isEmpty(stringBuilder.toString())) {
//                    stringBuilder.append(picPath);
//                } else {
//                    stringBuilder.append("&" + picPath);
//                }
//            }
//        }

//        if (TextUtils.isEmpty(info) && TextUtils.isEmpty(url)) {
//            ToastUtils.showShortToastSafe("提交信息不能为空");
//            return;
//        }

        ToastUtils.showShortToastSafe("正在提交,请稍后...");
        submitOrder = RetrofitHelper.getInstance().submitOrder(userid, orderId, info, url,"");
        submitOrder.enqueue(new Callback<BaseEntity>() {
            @Override
            public void onResponse(Call<BaseEntity> call, Response<BaseEntity> response) {
                if (response != null) {
                    BaseEntity body = response.body();
                    if (body != null) {
                        if ("100".equals(body.getCode())) {
                            ToastUtils.showShortToastSafe(body.getRinfo());
                            setResult(200);
                            finish();
                        } else {
                            ToastUtils.showShortToastSafe(body.getRinfo());
                        }
                    }
                }
            }

            @Override
            public void onFailure(Call<BaseEntity> call, Throwable t) {
                ToastUtils.showShortToastSafe(t.getMessage());
            }
        });


    }

    private List<UploadPicEntity> students = new ArrayList<>();

    /**
     * 提交任务新
     */
    public void submitOrderNew() {
        if (mData == null) {
            ToastUtils.showShortToastSafe("获取数据失败");
            return;
        }

        for (SubmitOrderDetailEntity.OrderinfoBean.TaskstepBean item : mData) {
            if(item.getFlag().equals("1")) {
                if (TextUtils.isEmpty(item.getTj_url())) {
                    ToastUtils.showShortToastSafe("请上传所需截图");
                    return;
                }
            }
        }
        if(isinfo.equals("1")){
          String str=  et_tj.getText().toString();
          if(str==null||str.length()==0){
              ToastUtils.showShortToastSafe("请提交说明");
              return;
          }

        }


        for (SubmitOrderDetailEntity.OrderinfoBean.TaskstepBean item : mData) {
            UploadPicEntity uploadPicEntity = new UploadPicEntity();
            uploadPicEntity.setOrder_pic(item.getTj_url());
            uploadPicEntity.setTp_id("" + item.getTp_id());
            students.add(uploadPicEntity);
        }

        String jsonStr = new Gson().toJson(students);
        String info = et_tj.getText().toString().trim();

        ToastUtils.showShortToastSafe("正在提交,请稍后...");

        Logger.e("xuke", "userid=" + userid);
        Logger.e("xuke", "orderId=" + orderId);
        Logger.e("xuke", "info=" + info);
        Logger.e("xuke", "jsonStr=" + jsonStr);

        TreeMap<String,String> paraMap = new TreeMap<String,String>();
        paraMap.put("u_id",userid);
        paraMap.put("o_id",orderId);
        paraMap.put("info",info+"");
        paraMap.put("picstr",jsonStr+"");
        String sign= SignUtil.generateSignature(paraMap, Constant.VALUE);
        submitOrder = RetrofitHelper.getInstance().submitOrder(userid, orderId, info, jsonStr,sign);
        submitOrder.enqueue(new Callback<BaseEntity>() {
            @Override
            public void onResponse(Call<BaseEntity> call, Response<BaseEntity> response) {
                if (response != null) {
                    BaseEntity body = response.body();
                    if (body != null) {
                        if ("100".equals(body.getCode())) {
                            ToastUtils.showShortToastSafe(body.getRinfo());
                            setResult(200);
                            finish();
                        } else {
                            ToastUtils.showShortToastSafe(body.getRinfo());
                        }
                    }
                }
            }

            @Override
            public void onFailure(Call<BaseEntity> call, Throwable t) {
                ToastUtils.showShortToastSafe(t.getMessage());
            }
        });


    }


    /**
     * 取消任务
     */
    public void setCancleOrder() {

        showProgress();
        cancleOrder = RetrofitHelper.getInstance().cancleOrder(userid, orderId);
        cancleOrder.enqueue(new Callback<BaseEntity>() {
            @Override
            public void onResponse(Call<BaseEntity> call, Response<BaseEntity> response) {
                if (response != null) {
                    BaseEntity body = response.body();
                    if (body != null) {
                        if ("100".equals(body.getCode())) {
                            ToastUtils.showShortToastSafe(body.getRinfo());
                            setResult(200);
                            finish();
                        } else {
                            ToastUtils.showShortToastSafe(body.getRinfo());
                        }
                    }
                    dismissProgress();

                }
            }

            @Override
            public void onFailure(Call<BaseEntity> call, Throwable t) {
                ToastUtils.showShortToastSafe(t.getMessage());
                dismissProgress();
            }
        });


    }

    /**
     用户投诉发布者
     */
    public void setAppealOrder(String text) {
        showProgress();
        cancleOrder = RetrofitHelper.getInstance().setAppeal(userid, orderId,text);
        cancleOrder.enqueue(new Callback<BaseEntity>() {
            @Override
            public void onResponse(Call<BaseEntity> call, Response<BaseEntity> response) {
                if (response != null) {
                    BaseEntity body = response.body();
                    if (body != null) {
                        if ("100".equals(body.getCode())) {
                            ToastUtils.showShortToastSafe(body.getRinfo());
                            setResult(200);
                            finish();
                        } else {
                            ToastUtils.showShortToastSafe(body.getRinfo());
                        }
                    }
                    dismissProgress();

                }
            }

            @Override
            public void onFailure(Call<BaseEntity> call, Throwable t) {
                ToastUtils.showShortToastSafe(t.getMessage());
                dismissProgress();
            }
        });


    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (taskDetail != null) {
            taskDetail.cancel();
        }
        if (cancleOrder != null) {
            cancleOrder.cancel();
        }
        if (submitOrder != null) {
            submitOrder.cancel();
        }
    }

    @Override
    public void onItemClick(View view, int position) {
        switch (position) {
            case IMAGE_ITEM_ADD:
                pickImage();
                break;
            default:
                //打开预览
                Intent intentPreview = new Intent(this, ImagePreviewDelActivity.class);
                intentPreview.putExtra(ImagePicker.EXTRA_IMAGE_ITEMS, (ArrayList<ImageItem>) adapter.getImages());
                intentPreview.putExtra(ImagePicker.EXTRA_SELECTED_IMAGE_POSITION, position);
                intentPreview.putExtra(ImagePicker.EXTRA_FROM_ITEMS, true);
                startActivityForResult(intentPreview, REQUEST_CODE_PREVIEW);
                break;
        }

    }

    private void pickImage() {
        //打开选择,本次允许选择的数量
        ImagePicker.getInstance().setSelectLimit(maxImgCount - selImageList.size());
        ImagePicker.getInstance().setCrop(false);
        ImagePicker.getInstance().setShowCamera(true);
        ImagePicker.getInstance().setMultiMode(true);
        Intent intent1 = new Intent(context, ImageGridActivity.class);
        startActivityForResult(intent1, REQUEST_CODE_SELECT);
    }

    @SuppressWarnings("unchecked")
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == ImagePicker.RESULT_CODE_ITEMS) {
            //添加图片返回
            if (data != null && requestCode == REQUEST_CODE_SELECT) {
                ArrayList<ImageItem> images = (ArrayList<ImageItem>) data.getSerializableExtra(ImagePicker.EXTRA_RESULT_ITEMS);
                if (images != null) {
                    selImageList.addAll(images);
                    adapter.setImages(selImageList);
                }
            }
        } else if (resultCode == ImagePicker.RESULT_CODE_BACK) {
            //预览图片返回
            if (data != null && requestCode == REQUEST_CODE_PREVIEW) {
                ArrayList<ImageItem> images = (ArrayList<ImageItem>) data.getSerializableExtra(ImagePicker.EXTRA_IMAGE_ITEMS);
                if (images != null) {
                    selImageList.clear();
                    selImageList.addAll(images);
                    adapter.setImages(selImageList);
                }
            }
        }

        if (resultCode == ImagePicker.RESULT_CODE_ITEMS) {
            //添加图片返回
            if (data != null && requestCode == 201) {
                ArrayList<ImageItem> images = (ArrayList<ImageItem>) data.getSerializableExtra(ImagePicker.EXTRA_RESULT_ITEMS);
                if (images != null) {
                    Logger.e("xuke", "--->" + images.get(0));

                    showProgress();
                    appPresenter.submituploadfile(new File(images.get(0).getPath()), ConstantValue.RequestKey.uploadfile);

                }
            }
        }

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @Override
    public void onSuccess(String code, String msg, Object data, String actionType) {
        dismissProgress();
        if (ConstantValue.RequestKey.uploadfiles.equals(actionType)) {
            List<UploadFilesEntity> list = (List<UploadFilesEntity>) data;

            if (list != null && list.size() > 0) {

                Logger.e("xuke", "list=" + list.size());
                StringBuilder stringBuilder = new StringBuilder("");
                for (int i = 0; i < list.size(); i++) {
                    UploadFilesEntity uploadFilesEntity = list.get(i);
                    String url = uploadFilesEntity.getUrl();


                    if (TextUtils.isEmpty(stringBuilder.toString())) {
                        stringBuilder.append(url);
                    } else {
                        stringBuilder.append("," + url);
                    }
                }
                String s = stringBuilder.toString();
                Logger.e("xuke", "s=" + s);
                //fabu(s);
                submitOrder(s);
            }

            //String data1 = (String) data;
            //submitOrder(data1);
        }

        dismissProgress();
        if (ConstantValue.RequestKey.uploadfile.equals(actionType)) {
            String url = (String) data;
            Logger.e("xuke", "url=" + url);
            if (mData != null) {
                SubmitOrderDetailEntity.OrderinfoBean.TaskstepBean taskstepBean = mData.get(nowPosition);
                taskstepBean.setTj_url(url);
                detailAdapter.refresh(mData);
            }
        }
    }

    @Override
    public void onFailed(String code, String msg) {
        dismissProgress();
        ToastUtils.showShortToastSafe(msg);
    }
}
